package com.lkd.controller;

import com.lkd.dto.PartnerDto;
import com.lkd.entity.Partner;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.PartnerService;
import com.lkd.vo.PartnerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PartnerController extends Result {

    @Autowired
    private PartnerService partnerService;

    /**
     * 创建新的合作伙伴
     */
    @PostMapping("/api/user-service/partner")
    public Result create(@RequestBody Partner partner) {
        boolean b = partnerService.create(partner);
        return Result.success(b);
    }

    /**
     * 根据ID更新现有合作伙伴
     */
    @PutMapping("/api/user-service/partner")
    public Result update(@RequestBody Partner partner) {
        boolean b = partnerService.update(partner);
        return Result.success(b);
    }

    /**
     * 根据ID删除合作伙伴
     */
    @DeleteMapping("/api/user-service/partner/{id}")
    public Result delete(@PathVariable Long id) {
        boolean b = partnerService.delete(id);
        return Result.success(b);
    }

    /**
     * 根据ID获取合作伙伴
     */
    @GetMapping("/api/user-service/partner/{id}")
    public Result getPartnerById(@PathVariable Long id) {
        Partner partner = partnerService.getById(id);
        return Result.success(partner);
    }

    /**
     * 合作商搜索
     */
    @GetMapping("/api/user-service/partner/search")
    public Result findByPage(PartnerDto dto) {
        PageBean<PartnerVo> pageBean = partnerService.findByPage(dto);
        return Result.success(pageBean);
    }
}
